using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using SouthernLand.Common;
using SouthernLand.Common.BOL.Articles;

namespace SouthernLand.Controls
{
    public partial class ArticlesMenu : UserControl
    {
        public int CateID = -1;

        protected void Page_Load(object sender, EventArgs e)
        {
            List<Article> lstArticles = Article.NhieuNguoiQuanTam();
            if (lstArticles != null && lstArticles.Count > 0)
            {
                rptNewsMenu.DataSource = lstArticles;
                rptNewsMenu.DataBind();
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            rptNewsMenu.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(rptNewsMenu_ItemDataBound);
        }

        void rptNewsMenu_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Article article = (Article) e.Item.DataItem;
                HyperLink hplNewsTitle = (HyperLink) e.Item.FindControl("hplNewsTitle");
                hplNewsTitle.Text = article.Title;
                hplNewsTitle.NavigateUrl = Globals.BuildUrlByNews(article.ArticleID,
                                                                  Globals.ProcessString(
                                                                      Globals.UnicodeToKoDau(article.Title)));
                HyperLink hplNewsImage = (HyperLink) e.Item.FindControl("hplNewsImage");
                hplNewsImage.NavigateUrl = Globals.BuildUrlByNews(article.ArticleID,
                                                                  Globals.ProcessString(
                                                                      Globals.UnicodeToKoDau(article.Title)));
                Image imgNews = (Image) e.Item.FindControl("imgNews");
                imgNews.ImageUrl = Globals.ApplicationPath + "UserUpload/Articles/" + article.ImageURL;
            }
        }
    }
}